﻿using System.Runtime.Serialization;

namespace ServerUtils
{
    [DataContract]
    public class OperationResult<TData> : OperationResult
    {
        [DataMember]
        public TData Data { get; set; }

        public static new OperationResult<TData> Succeed(TData data)
        {
            return new OperationResult<TData> { ResultType = OperationResultType.Succeed, Data = data };
        }

        public new static OperationResult<TData> Failed(string message)
        {
            return new OperationResult<TData> { ResultType = OperationResultType.Failed, Message = message };
        }

        public new static OperationResult<TData> Failed(string format, params object[] args)
        {
            return Failed(string.Format(format, args));
        }

        public new static OperationResult<TData> Error(string message)
        {
            return new OperationResult<TData> { ResultType = OperationResultType.Error, Message = message };
        }

        public new static OperationResult<TData> Error(string format, params object[] args)
        {
            return Error(string.Format(format, args));
        }

        public override string ToString()
        {
            var dataText = this.Data != null ? this.Data.ToString() : "null";
            return string.Format("{0}, Data: {1}", base.ToString(), dataText);
        }
    }
}
